// index.js
// 获取应用实例
import config from '../../utils/config.js'
import util from '../../utils/util.js'
const app = getApp()
Page({
  data: {
    order: false,
    endPage: false,
    videoEnd:false, // 视频是否播放结算
    videoUrl:config.videoUrl
  },
  onLoad() {
    wx.getSystemInfo({
      success: (result) => {
        this.setData({
          width: result.windowWidth,
          height: result.windowHeight,
        })
      },
    })
    this.login()
  },
  videoEndFun(e){
    console.log(e,'播放结束')
    this.setData({
      videoEnd:true
    })
  },
  login() {
    wx.login({
      success(res) {
        console.log(res)
        if (res.code) {
          //发起网络请求
          let url = config.loginByCode
          let o = {
            code: res.code
          }
          util.ajax(url,o,(res)=>{
            console.log(res)
            if(res.data.code == 0){
              wx.setStorageSync('session3rd', res.data.data.session3rd)
              wx.setStorageSync('openid', res.data.data.openid)
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  },

  sureOrder() {
    this.setData({
      order: true
    })
    console.log(this.data.order)
  },
  goToEnd(e) {
    let val = e.detail.params
    console.log(e, val)
    this.setData({
      endPage: val
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: app.data.share_title,
      path: app.data.path,
      imageUrl: app.data.share_image,
    }
  }
})